
== Mangosweb Scripting structure Documentation ==





== Style of code ==
On the CodingStyle page, you can find all about our code style requirements (be sure to read them before you commit your changes).

[[BR]]
[[BR]]
[[BR]]

== Database connections ==

''Mangosweb uses the same database structure as the newest MaNGOS source. In MaNGOS source there are 2 databases, known as World database and Realm database. Mangosweb uses them both to retrieve/update/add data.''
[[BR]]
Mangosweb uses a database Class to retrieve and update data in databases. Classes to both of the databases that mangosweb is using are defined as $WSDB and $DB. $WSDB is obiously the World database and visa versa.
[[BR]][[BR]]
'''World database'''
Php variable: $WSDB->YOUR_CLASS_CALL
Desc: Connects and does what you want with the world database.
[[BR]][[BR]]
'''Realm Database'''
Php variable: $DB->YOUR_CLASS_CALL
Desc: connects and does what you want with the REALM database.



'''Database Class information'''

''As known, MangosWeb uses a database class to do querys from the PHP scripts. Here are some basic explaination. ''[[BR]]
Our example is, how to use $DB variable to get /update / delete things.[[BR]]
From the table below you can see a table with the class function, here is an example of how to use it: "$DB->select("SELECT * FROM accounts");"[[BR]]

||ClassCall||Return Type||Return Detail||Further information||
||select||Array||Returns the array generated from the database query||Use select if its more than one row that you want to get||
||selectRow||Array||Returns the array generated from database query||Use selectRow if its only ONE (1) Row that you want out.||
||selectCell||String||Returns the spesific Cell of database you want|| Use selectCell if its only a Cell you want printed exm: SELECT id FROM account WHERE id=1
||query||Bool||Returns TRUE or FALSE||Returns TRUE if query was OK , returns FALSE if querys was not OK, you can do all querys in here ( UPDATE / DELETE )||

'''Example 1: If you want to delete all accounts:'''[[BR]]

{{{
if ($DB->query("TRUNCATE TABLE `account`") == TRUE){
    echo "All accounts were deleted.";
}
}}}

'''Example 2: if you want to find how many characters the the user has and print it:'''[[BR]]

{{{
$users_email = $DB->selectCell("SELECT numchars FROM `realmcharacters` WHERE acctid=?d",$user['id']);
echo $users_email;
}}}

'''Example 3: Connecting to world database; find all characters to the loggedin user, make it an array and print name of all characters:'''[[BR]]

{{{
$rows = $WSDB->select("SELECT * FROM `characters` WHERE account_id=?d", $user['id']);
foreach($rows as $row){
echo $row['name'];
}
}}}


[[BR]]
[[BR]]
[[BR]]

== Global Variables ==
''Global variables are variables who does not change, NEVER create a variable simular to these. Also please keep this list up to date.''
||Variable name||Variable type||What it does?||
||$user||Array||The variable user is defined as the logged in user, the user variable got all information that is stored in realm - >`account` table. Example: $user!['id'] holds what ID the user has, $user!['email'] holds the email to the user. If $user!['id'] = 0, this means that the user is not logged in.||
||$MANGOS_SELECTED_REALM||INT||Holds information on what REALM to view. If user is logged on it depend on the "realm.account_extend.viewing_server" else its defined in config![realminfo][default_realm_id].||
||{{{$_REQUEST['n']}}}||string||This is used to request and show main categorys on screen||?||
||{{{$_REQUEST['sub']}}}||string||This is used to request and show Sub categorys on screen||?||







[[BR]]
[[BR]]
To be continued.